local rd__daizui = fk.CreateSkill {
    name = "rd__daizui",
    dynamic_desc = function(self, player, lang)
        return "rd__daizui_inner:" .. player:getMark("rd__daizui_times-turn")
    end,
}

Fk:loadTranslationTable {
    ["rd__daizui"] = "戴罪",
    [":rd__daizui"] = "出牌阶段限零次，你可以重置自己一个技能的使用次数。你的回合内，你每造成两点伤害，此技能使用次数+1。",
    [":rd__daizui_inner"] = "出牌阶段限{1}次，你可以重置自己一个技能的使用次数。你的回合内，你每造成两点伤害，此技能使用次数+1。",
    ["#rd__daizui"] = "戴罪：重置自己一个技能的使用次数！",

    ["$rd__daizui1"] = "望丞相权且记过，容干将功折罪啊！",
    ["$rd__daizui2"] = "干，谢丞相不杀之恩！",
}

rd__daizui:addEffect("active", {
    anim_type = "offensive",
    card_num = 0,
    target_num = 0,
    times = function(self)
        return Self:getMark("rd__daizui_times-turn") or 0
    end,
    can_use = function(self, player)
        return player:getMark("rd__daizui_times-turn") > 0
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local skills = {}
        for _, s in ipairs(player:getAllSkills()) do
            if s:isInstanceOf(ActiveSkill) and s.name ~= nil then
                table.insert(skills, s.name)
            end
        end
        if #skills == 0 then return end
        local choice = room:askToChoice(player, {
            choices = skills,
            skill_name = rd__daizui.name,
            prompt = "#rd__daizui",
        })
        local skillName = Fk.skills[choice].name
        player:setSkillUseHistory(skillName, 0, Player.HistoryPhase)
        room:addPlayerMark(player, "rd__daizui_times-turn", -1)
    end,
})

rd__daizui:addEffect(fk.Damage, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player.phase == Player.Play and player:hasSkill("rd__daizui")
    end,
    on_trigger = function(self, event, target, player, data)
        local damage = data
        local room = player.room
        local current = player:getMark("rd__daizui_damage-turn") or 0
        current = current + damage.damage
        local added = math.floor(current / 2)
        if added > 0 then
            room:addPlayerMark(player, "rd__daizui_times-turn", added)
        end
        room:setPlayerMark(player, "rd__daizui_damage-turn", current % 2)
    end,
})

rd__daizui:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player.phase == Player.NotActive and player:hasSkill("rd__daizui")
    end,
    on_trigger = function(self, event, target, player, data)
        player.room:setPlayerMark(player, "rd__daizui_times-turn", 0)
        player.room:setPlayerMark(player, "rd__daizui_damage-turn", 0)
    end,
})

return rd__daizui
